package test.web;

import java.util.List;

import org.junit.Test;

import com.alibaba.fastjson.JSON;

import hyl.core.MyFun;
import hyl.core.fun.MyByte;
import hyl.core.io.MyFile;
import hyl.ext.ws.msg.Msgpg;
import hyl.ext.ws.msg.MsgpgStream;
import hyl.ext.ws.msg.WsMsgS;

public class testwebmsg {
	 @Test
	public void test001() {
		String _会话目录 = "./tempmsg/";
		WsMsgS mi = WsMsgS.getInstance(null);
		mi.setMsg("2", "1->2", "买买买1");
		System.out.println(mi.toSendString());
		MyFile.appendBytes(_会话目录 + mi.接收方, mi.encode());
		mi = WsMsgS.getInstance(null);
		mi.setMsg("2", "2->4", "买买买2");
		System.out.println(mi.toSendString());
		MyFile.appendBytes(_会话目录 + mi.接收方, mi.encode());
		System.out.println("------------------------------");
		List<WsMsgS> msgSs = WsMsgS.loadMsgs(MyFile.readAllBytes(_会话目录 + "2"));
		MyFile.deleteFile(_会话目录 + "2");
		MyFun.printJson(msgSs);
	}

	//@Test
	public void test002() {
		String _会话目录 = "./tempmsg/";
		Msgpg mi = Msgpg.create系统消息(null);
		mi.setMsg("2", "1->2", "买12354到时候噶是大哥生气的话噶啥生活的风格买买1".getBytes());
		MyFun.printJson(mi);
		//MyFile.appendBytes(_会话目录 + mi.接收方, mi.toSendBytes());
		Msgpg mi2 = Msgpg.create系统消息(null);
		mi2.setMsg("2", "2->4", "买买12354到时候噶是大哥生气的话噶啥生活的风格买买12".getBytes());
		MyFun.printJson(mi2);
		//MyFile.appendBytes(_会话目录 + mi2.接收方, mi2.toSendBytes());
		System.out.println("------------------------------");
		byte[] b1=MyFun.concat( mi.toSendBytes(), mi2.toSendBytes());
		//System.out.println(mi.length());
	//	System.out.println(mi2.length());
	//	System.out.println(b1.length);
		MsgpgStream wmbs=	MsgpgStream.getInstance();
		wmbs.add碎片(MyByte.subBytes(b1, 0, 10));
		wmbs.add碎片(MyByte.subBytes(b1, 10));
		//MyFile.deleteFile(_会话目录 + "2");
//		wmbs.foreach((ws)->{
//			MyFun.print(MyFun.bytes2U8str(ws.内容));
//			MyFun.printJson(ws);
//		});
		wmbs.clearList();
		MyFun.printJson(wmbs.toList());
	}
}
